﻿using System.Collections.Generic;
using Ext.Net.Utilities;

namespace KamLib
{

    public class PageNode
    {
        public string Url { get; set; }
        public string LID { get; set; }
        public string Title { get; set; }
        public string PageTitle { get; set; }
        public string Icon { get; set; }
        public string Desc { get; set; }
        public string TabTip { get; set; }

        public string BgColor { get; set; }
        public string BorderColor { get; set; }
        public string Click { get; set; }
        public string TabTitle { get; set; }

        public bool Collapsed { get; set; }

        public int Index { get; set; }

        public List<PageNode> Items = new List<PageNode>();
    }


    public static class PageNodeHelper
    {
        public static PageNode[] PrepareAsGroups(this PageNode[] pages)
        {
            var i = 0;
            foreach (var page in pages)
            {
                page.Index = i++;
                if (page.Items==null) continue;
                var tabIndex = 0;
                foreach (var item in page.Items)
                {
                    item.Index = item.LID.IsEmpty() ? -1 : tabIndex++;
                }
            }

            return pages;
        }
    }
}
